import { existsSync } from 'node:fs';
import { resolve } from 'node:path';

/**
 * 包版本管理器配置对照表
 * **/
const packageMangerViewer = new Map([
    ['yarn', 'yarn.lock'],
    ['npm', 'package-lock.json'],
    ['pnpm', 'pnpm-lock.yaml']
]);
/**
 * 获取当前项目的包版本管理器, 目前支持 yarn|npm|pnpm
 * @param { string } targetPath 目标路径
 * **/
const getPackageMangerName = (targetPath = process.cwd()) => {
    for (const [key, value] of packageMangerViewer) {
        if (existsSync(resolve(targetPath, value))) {
            return key;
        }
    }
};

export { getPackageMangerName, packageMangerViewer };
